﻿namespace DimensionsHelper.ExcelAddIn.Core;

internal static class Extensions
{

    public static T[,] ToExcelRow<T>(this T[] values)
    {
        T[,] excelArray = new T[1, values.Length];

        for (int i = 0; i < values.Length; i++)
        {
            excelArray[0, i] = values[i];
        }

        return excelArray;
    }


    public static T[,] ToExcelRow<T>(this ICollection<T> collection)
    {
        T[,] excelArray = new T[1, collection.Count];
        int i = 0;
        foreach (var item in collection)
        {
            excelArray[0, i] = item;
            i++;
        }
        return excelArray;
    }


    public static T[,] ToExcelColumn<T>(this T[] values)
    {
        T[,] excelArray = new T[values.Length, 1];
    
        for (int i = 0; i < values.Length; i++)
        {
            excelArray[i, 0] = values[i];
        }

        return excelArray;
    }


    public static T[,] ToExcelColumn<T>(this ICollection<T> collection)
    {
        T[,] excelArray = new T[collection.Count, 1];
        int i = 0;
        foreach (var item in collection)
        {
            excelArray[i, 0] = item;
            i++;
        }
        return excelArray;
    }


    public static void AddOrUpdate<TK, TV>(this IDictionary<TK, TV> dictionary, TK key, TV value)
    {
        dictionary[key] = value;
    }

}
